name: Poetry Test
on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - master
      - 'releases/**'
  pull_request:
    branches:
      - master
      - 'releases/**'
jobs:
  poetry-build-test:
    runs-on: ubuntu-latest
    steps:
      - name: Set up Python 3.10
        uses: actions/setup-python@v4
        with:
          python-version: '3.10'
      - name: Install Poetry
        run: |
          curl -sSL https://install.python-poetry.org | python -
          echo "$HOME/.poetry/bin" >> $GITHUB_PATH
      - name: Create foo package
        run: |
          mkdir foo
          MASTER_REPO_URL=${{ github.server_url }}/${{ github.repository }}
          REPO_URL=${{ github.event.pull_request.head.repo.html_url }}
          if [ -z "$REPO_URL" ]; then
            # This is a push, not a PR, so use the repo URL
            REPO_URL=$MASTER_REPO_URL
          fi
          echo Master repo URL: $MASTER_REPO_URL
          echo Using repo URL: $REPO_URL
          cat <<EOF > foo/pyproject.toml
          [tool.poetry]
          name = "foo"
          version = "1.0.0"
          authors = ["skypilot-bot"]
          description = ""

          [tool.poetry.dependencies]
          python = "3.10.x"

          [tool.poetry.group.dev.dependencies]
          skypilot = {git = "${REPO_URL}.git", branch = "${{ github.head_ref }}"}

          [build-system]
          requires = ["poetry-core"]
          build-backend = "poetry.core.masonry.api"
          
          EOF

      - name: Check poetry lock time
        run: |
          cd foo
          poetry lock --no-update
        timeout-minutes: 2


